<%@page import="org.biojava.services.das.dao.CourseManager"%>
<jsp:directive.page session="true" />
<%@ page import="org.biojava.services.das.dao.RegistryUser" %>
<%@ page import="org.biojava.services.das.registry.UserManager" %>
<%@ page import="org.biojava.services.das.dao.ProjectBean"%>
<jsp:directive.page import="org.biojava.services.das.registry.DasRegistrySql" />
<jsp:directive.page import="org.biojava.dasobert.dasregistry.DasSource" />
<jsp:directive.page import="java.util.List" />
<jsp:useBean id="coord" class="dasregistry.coordBean" scope="page"/>
<jsp:directive.page import="org.springframework.beans.factory.BeanFactory"/>
<jsp:directive.page import="org.springframework.context.support.ClassPathXmlApplicationContext"/>
<%@ include file="sangerheader.jsp"%>
<% 

BeanFactory ctax=(new ClassPathXmlApplicationContext("SpringDAO.xml"));
DasRegistrySql registry=(DasRegistrySql)ctax.getBean("registryBean");
   
    String action=request.getParameter("action");
  //System.out.println("email="+email+" action="+action);
    
	if ( email == null) {
		//if email is null then we must be registering a new user
		action="create";
		//return;
	}
	UserManager uml = (UserManager)ctax.getBean("userManager");
	if ( uml.isNewUser(email) ){
		response.sendRedirect("loginFirst.jsp");	
		return;
	}
	
	RegistryUser userl = uml.getUser(email);

	
	ProjectBean[]	projects = coord.getProjectsForUser(userl);
	int adminLength = coord.getAdminProjectsForUser(userl).length;
	
%>

<%
	String title = "Login Settings for DAS registry";
	String header = title;
%>


<!-- the sanger default header -->


<div id="main">

<%
if (request.getParameter("message") != null) {
%>
<p><strong><%=request.getParameter("message")%></strong></p>
<%
}
%>


<br />
You are logged in as <%
if ( isAdmin ) {
	%><strong>admin user</strong> <% 
}
%>
<b><%=session.getAttribute("email")%></b> <br />
<br />

<h2>Your login settings are:</h2>


<form method="POST" action="loginFirstAction.jsp?action=<%=action%>">
<input type="hidden" value="<%=user.getUserID()%>" name="user_id"/>
<table>
<tr><td>email:</td>
<td></td>
<td><input class="email" type="text" size="40" name="newemail" value="<%=user.getEmail()%>"></td>
</tr>
<tr>
<td>Display name:</td>
<td></td>
<td><input class="displayName" type="text" size="40" name="email" value="<%=user.getOpenID()%>"></td>
</tr>
<tr><td>alert me if my DAS sources are down:</td>
<td><img src="img/mail_forward.png"></td>
<td><input type="checkbox" name="watchdog" value="1" <%
	if ( user.isAlertMe() )
		out.print("checked");
%>> </td></tr>
</table>
<input type="submit" value="update account"/>
</form>

<p/>

<h2>My DAS sources</h2>
Currently <a href="listServices.jsp?cmd=showmine"><% 

		List<DasSource> sources = registry.getServicesForEmail(email);
		out.print(sources.size());
%> DAS source(s)</a> are linked to this account.

<p/>

<h2>My Projects</h2>
Currently <a href="listProjects.jsp?cmd=showmine"><%=projects.length %></a>
 project(s) are linked to this account. You are administrator of 
 <a href="listProjects.jsp?cmd=showmine"><%=adminLength %></a>.

<p/>


<h2>Delete your email account</h2>


<script type="text/javascript">
<!--
function confirmation() {
	var answer = confirm("Are you sure you want to delete your account?")
	if (answer){
		return true;	
	}
	else{
		return false;
	}
}
//-->
</script>

Warning! If you press the Delete button your email account will be removed from the DAS registration server.

<form method="POST" action="loginFirstAction.jsp?action=delete" name="dasregistry-remove-account">
<input type="submit" value="remove account" onclick="return confirmation();"/>
</form>


</div>


<%@ include file="sangerfooter.jsp"%>